Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-yaml

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-yaml

A wrapper for js-yaml parser

  • 3.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
82K
increased by14%
Maintainers
1
Weekly downloads
 
Created
Source

Node YAML

A wrapper for js-yaml parser

Installation

You can install this module using NPM:

  npm install --save node-yaml

API

yaml.read(file[, options, callback])

Read and parse YAML file.

  • file Path to file or file descriptor
  • null|string|object Options:
    • [string] encoding (default = utf8)
    • [object] schema - specifies a schema to use. More information about this option here (default - defaultSafe).
      • defaultSafe - all supported YAML types, without unsafe ones
      • defaultFull - all supported YAML types
      • failsafe - only strings, arrays and plain objects
      • json - all JSON-supported types
      • core - same as json schema
  yaml = require "node-yaml"

  yaml.read "path/to/file.yaml",
    encoding: "utf8"
    schema: yaml.schema.defaultSafe, (err, data) ->
      throw err if err

      console.log data

Note: You also can use path without file extension (only for yaml.read and yaml.readSync).

Note: yaml.schema.defaultSafe schema used by default because is that recomended loading way.

yaml.readSync(file[, options])

Synchronous version of yaml.read. Return the contents of the file

yaml.write(file, data[, options, callback])

Parse and write YAML to file.

  • int|string file - Path to file or file descriptor
  • object data - Some data to write
  • null|string|object options:
    • [string] encoding (default = utf8)
    • [object] schema - specifies a schema to use. More information about this option here (default - defaultSafe).
      • defaultSafe - all supported YAML types, without unsafe ones
      • defaultFull - all supported YAML types
      • failsafe - only strings, arrays and plain objects
      • json - all JSON-supported types
      • core - same as json schema
  {write} = require "node-yaml"

  data =
    foo: "foo"
    bar: "bar"

  write "path/to/file.yaml", data, "utf8", (err) -> throw err if err

yaml.writeSync(file, data[, options])

Synchronous version of yaml.write.

yaml.parse(string[, options])

Parse YAML.

  • string - YAML string to parse
  • [object] options:
    • [object] schema
  {parse} = require "node-yaml"

  data = """
    foo: foo
    bar: bar
  """

  console.log parse data

yaml.dump(json[, options])

Convert JSON into YAML.

  {dump} = require "node-yaml"

  data =
    foo: "foo"
    bar: "bar"

  console.log dump data

Keywords

FAQs

Package last updated on 28 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc